package model.server;

import java.io.ObjectOutputStream;
import java.util.HashMap;
import java.util.Map;

/**
 * 将客户端名称与对应socket储存到Map中，一一对应，保证服务器可以映射请求
 * 使用单例模式，保证服务器运行期间的Map是同一个
 */
public class ChatManager {
    private static final ChatManager instance = new ChatManager();
    private Map<String, ObjectOutputStream> map = new HashMap<>();

    private ChatManager() {

    }

    public static ChatManager getInstance() {
        return instance;
    }

    public void add(String name, ObjectOutputStream out) {
        map.put(name, out);
    }

    public void remove(String name) {
        map.remove(name);
    }

    public Map<String, ObjectOutputStream> getMap() {
        return map;
    }
}
